$(function () {
    getCouponList(1);

    function getCouponList(pageNo) {
        var params = '';
        var obj={
            url: baseloaction + '/mobile/uc/op/coupon/myAjaxCoupon',//请求url
            contextId:'coupon-list-box',//请求成功后数据内容添加的地方
            pageNo:pageNo,//页面码，可以不传
            pageCall:getCouponList,//分页方法（一般调用自身）
            params:params,//查询参数
            callback:function (pageNo) {}
        };
        loadMobilePathData(obj);
    }

    $("body").on("click",".packUp",function () {
        var that = $(this);
        var sparent = that.parents('li').find(".Coupon-about-desc__wrap");
        //收起
        if(that.find(".icon-up").length>0){
            that.find(".icon-up").removeClass("icon-up").addClass("icon-down");
            sparent.addClass('hide');
        }else{
            that.find(".icon-down").removeClass("icon-down").addClass("icon-up");
            sparent.removeClass('hide');
            var couponId = that.data('coupon');
            var codeId = that.data('id');
            showCouponShopData(couponId,codeId);
        }
    }).on("click","#openCoupon",function () {
        $.findCouponList(true);
    });
    var showCouponStatus = {}
    /**
     * 获取优惠券关联的商品数据
     * @param couponId 优惠券ID
     * @param codeId 编码ID
     */
    function showCouponShopData(couponId,codeId) {
        var status = showCouponStatus[codeId];
        if(status ==true){
            return;
        }
        $.ajax({
            url: baseloaction + '/mobile/uc/op/coupon/showCouponShopData',
            type:'post',
            dataType:'json',
            data:{
                'couponId': couponId
            },
            success:function (result) {
                if(result.success==true){
                    showCouponStatus[codeId] = true;
                    var list = result.entity;
                    if(list!=null && list.length > 0){
                        var context = '';
                        $.each(list,function (index,shop) {
                            var suffix = '';
                            var shopName = '';
                            if(shop.shopType=='COURSE'){
                                suffix = '[课程]';
                                shopName = shop.shop.shopName;
                            }else if(shop.shopType=='EXAM'){
                                shopName = shop.shop.shopName;
                                suffix = '[试卷]';
                            }else if(shop.shopType=='BOOK'){
                                shopName = shop.shop.shopName;
                                suffix = '[图书]';
                            }else if(shop.shopType=='MEMBER'){
                                shopName = shop.shop.shopName;
                                suffix = '[会员]';
                            }else if(shop.shopType=='QA'){
                                shopName = '付费问答';
                            }else if(shop.shopType=='ATTEND'){
                                shopName = '问答旁听';
                            }
                            context +='<span>《'+suffix+shopName+'》</span>';
                        });
                        $("#show-shop-"+codeId).append(context);
                    }
                }else{
                    $.toast(result.message);
                }
            },
            error:function (error) {
                $.toast("系统错误，查看优惠券适用商品范围失败");
            }
        });
    }
});



